package com.example.server.config;

import com.example.server.service.CxfService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.xml.ws.Endpoint;

/**
 * @Author: YAOZUN
 * @Date: Created in 20:21 2018/12/15 0015
 * @Description:
 */
@Configuration
public class CxfServiceConfig {

    @Autowired
    private Bus bus;

    @Resource
    private CxfService cxfService;

    @Bean
    public ServletRegistrationBean cfxDispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
    }

    //此处要注意导入正取的Endpoint、EndpointImpl包
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, cxfService);
        endpoint.publish("/user");
        return endpoint;
    }

}
